package com.plm.maque.common.pay;

import com.alipay.api.AlipayClient;
import com.alipay.api.DefaultAlipayClient;
import lombok.Getter;
import lombok.Setter;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.PropertySource;
import org.springframework.stereotype.Component;

/**
 * @author Limi
 * @create 2020-06-29 9:44
 */
@Getter
@Setter
@Component
@PropertySource(value = "classpath:pay.properties")
@ConfigurationProperties(prefix = "alipay")
public class AlipayUtil {

    private String serverurl;
    private String appId;
    private String privateKey;
    private String publicKey;
    private String format;
    private String charset;
    private String alipayPublicKey;
    private String signType;
    private String notifyUrl;

    public static AlipayClient alipayClient;

    public static Integer outTradeNo = 100000000;


    public AlipayClient getAlipayClient(){
        if (alipayClient == null) {
            alipayClient = new DefaultAlipayClient(serverurl, appId, privateKey,
                    format, charset, alipayPublicKey, signType);
        }
        return alipayClient;
    }

    public static Integer outTradeNo(){
        return ++outTradeNo;
    }

}
